package com.rankeiot.core.util.castor;

public class CharacterCastor implements Castor<Character> {
    public static final CharacterCastor instance=new CharacterCastor();
    private CharacterCastor(){}
    @Override
    public Character cast(Object v) {
        if(v==null){
            return null;
        }
        if(v instanceof Character){
            return (Character) v;
        }
        if(char.class.isInstance(v)){
            return (char)v;
        }
        if(int.class.isInstance(v)||long.class.isInstance(v)||Integer.class.isInstance(v)||Long.class.isInstance(v)){
            return (char)v;
        }
        if(boolean.class.isInstance(v)||Boolean.class.isInstance(v)){
            return ((Boolean)v).booleanValue()?'1':'0';
        }
        if(v instanceof  String){
            String vStr=(String)v;
            if(vStr.length()>0){
                return vStr.charAt(0);
            }
            return null;
        }
        return null;
    }
}
